﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace A2DFramework.EventService
{
    internal static class XmlHelper
    {
        internal static object Deserialize(string xml, Type targetType)
        {
            object evt = null;
            using (StringReader rdr = new StringReader(xml))
            {
                XmlSerializer serializer = new XmlSerializer(targetType);
                evt = serializer.Deserialize(rdr);
            }
            return evt;
        }

        internal static string Serialize(Type targetType, object obj)
        {
            using (StringWriter sw = new StringWriter())
            {
                XmlSerializer xz = new XmlSerializer(targetType);
                xz.Serialize(sw, obj);
                return sw.ToString();
            }
        }
    }
}
